//
//  HCLogMessage.m
//  HCLog
//
//  Created by 韩昌 on 2017/7/11.
//  Copyright © 2017年 Han Chang. All rights reserved.
//

#import "HCLogMessage.h"
#import <pthread/pthread.h>

@interface HCLogMessage ()

@end

@implementation HCLogMessage

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (instancetype)initWithMessage:(NSString *)message
                          level:(HCLogLevel)level
                           flag:(HCLogFlag)flag
                        context:(NSInteger)context
                           file:(const char *)file
                       function:(const char *)function
                           line:(NSUInteger)line
                            tag:(NSString *)tag
                           date:(NSDate *)date
{
    if ((self = [super init])) {
        _message = message;
        _level = level;
        _flag = flag;
        _context = context;
        _file = [NSString stringWithFormat:@"%s", file];
        _function = [NSString stringWithFormat:@"%s", function];
        _line = line;
        _tag = tag;
        _date = date ?: [NSDate date];
        
        _processID = [NSString stringWithFormat:@"%d", (int)getpid()];
        
        uint64_t threadId = 0;
        if (pthread_threadid_np(0, &threadId) == 0) {
            _threadID = [[NSString alloc] initWithFormat:@"%llu", threadId];
        } else {
            _threadID = [[NSString alloc] initWithFormat:@"%x", pthread_mach_thread_np(pthread_self())];
        }
        
    }
    return self;
}

@end
